package user_view

import (
	"data_monitor/pkg/app"
	"data_monitor/pkg/user/user_model"
	"data_monitor/pkg/user/user_service"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SignIn(c *gin.Context) {
	appG := app.Gin{C: c}
	request := &SignInRequest{}

	if err := c.BindJSON(request); err!=nil{
		appG.Response(http.StatusBadRequest, app.ERROR, nil)
		return
	}

	m := &user_model.User{}
	request.CopyToModel(m)

	user, err := user_service.SignIn(m)
	if err != nil{
		appG.Response(http.StatusNotFound, app.ERROR, err)
		return
	}

	appG.Response(http.StatusOK, app.SUCCESS, map[string]interface{}{
		"user": user,
	})
}